import { getObjectValueOfKey } from './util';
import { LocalConfig } from '@/interfaces/config';

/**
 * 页面配置
 */
interface IWindow extends Window {
  __config: LocalConfig;
}

declare const window: IWindow;

export function getLocalConfig() {
  return window.__config;
}

/**
 * 获取配置
 * @param key
 * @param defaultValue
 */
export function getConfig<T = any>(key: string, defaultValue?: T) {
  const v = getObjectValueOfKey<T>(key, getLocalConfig());
  return v === null ? (typeof defaultValue === 'undefined' ? null : defaultValue) : v;
}
